<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>查看菜品</title>
    <link rel="stylesheet" type="text/css" href="/orderSystem/css/query.css" />
    <script type="text/javascript" src="/orderSystem/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var params=new URLSearchParams(window.location.search);
            var pageNo=params.get("pageNo");
            var likeValue=params.get("likeValue");
            selectByPage(pageNo,likeValue);
            $("#queryByLikeValue").click(function () {
                var str=$("#likeValueStr").val();
                selectByPage(1,str);
            })
        });
        function del(aNode) {
            var str=$(aNode).parent().parent().find("td").eq(1).text();
            if(!confirm("确定删除"+str+"的信息吗?"))
                event.preventDefault();

        }
        function selectByPage(pageNo,likeValue) {
            $("#dishesList").empty();
            var url="/orderSystem/selectByPage.dish";
            var params={"pageNo":pageNo,"likeValue":likeValue};
            $.post(url,params,function (data) {
                var JsonObj=JSON.parse(data);
                var recordList=JsonObj.recordList;
                for(var i=0;i<recordList.length;i++){
                    var dish=recordList[i];
                    $("<tr><td>"+dish.cid+"</td>"+
                        "<td>"+dish.dish_name+"</td>"+
                        "<td>"+dish.dish_type+"</td>"+
                        "<td>"+dish.dish_description+"</td>"+
                        "<td>"+dish.price+"</td>"+
                        "<td><a href='/orderSystem/toEdit.dish?cid="+dish.cid+"'>编辑</a></td>"+
                        "<td><a href='/orderSystem/deleteById.dish?cid="+dish.cid+"' onclick='del(this)'>删除</a></td>"+
                        "</tr>").appendTo($("#dishesList"))
                }
                $("#likeValueStr").val(JsonObj.likeValue);
                $("#recordCount").text(JsonObj.recordCount);
                $("#totalPages").text(JsonObj.totalPages);
                $("#pageNo").text(JsonObj.pageNo);
                $("#homePage").prop("href","/orderSystem/toList.dish?pageNo=1&likeValue="+JsonObj.likeValue);
                if(JsonObj.pageNo>1)
                    $("#priPage").prop("href","/orderSystem/toList.dish?pageNo="+(JsonObj.pageNo-1)+"&likeValue="+JsonObj.likeValue);
                if(JsonObj.pageNo<JsonObj.totalPages)
                    $("#nextPage").prop("href","/orderSystem/toList.dish?pageNo="+(JsonObj.pageNo+1)+"&likeValue="+JsonObj.likeValue);
                $("#tailPage").prop("href","/orderSystem/toList.dish?pageNo="+JsonObj.totalPages+"&likeValue="+JsonObj.likeValue);

            });
        }
    </script>
</head>
<body>
<div id="top">·当前位置： 菜品管理 -- 查看菜品</div>
<div id="contexttop" >
    <table id="tab" border="1">
        <tr>
            <td colspan="7" height="50">
                <input type="text" id="likeValueStr" placeholder="输入菜名、价格、描述查询">
                <input type="button" value="查询" id="queryByLikeValue">
            </td>
        </tr>
        <tr >
            <th>菜品编号</th>
            <th>菜品名称</th>
            <th>菜品类别</th>
            <th>菜品描述</th>
            <th>菜品价格</th>
            <th colspan="2">操作</th>
        </tr>
        <tbody id="dishesList"></tbody>
    </table>
</div>
<div align="center" id="contextbottom">
    &nbsp;总记录数&nbsp;<span id="recordCount"></span>&nbsp;条
    &nbsp;共&nbsp;<span id="totalPages"></span>&nbsp;页
    &nbsp;<a href="#" id="homePage">首页</a>
    &nbsp;<a href="#" id="priPage">上一页</a>
    &nbsp;<a href="#" id="nextPage">下一页</a>
    &nbsp;<a href="#" id="tailPage">尾页</a>
    &nbsp;第&nbsp;<span id="pageNo"></span>&nbsp;页&nbsp;
    <br/>
</div>
</body>
</html>